package com.espirit.eap.manager;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import com.googlecode.cswish.struts.spring.GenericService;

@Service
public class SequenceDataService {

	@Resource
	private GenericService genericService;
	
	@Transactional(isolation=Isolation.SERIALIZABLE)
	public int nextSeq(int id) {
		SequenceData sequenceData = genericService.load(SequenceData.class, id);
		if (sequenceData == null) {
			sequenceData = new SequenceData();
			sequenceData.setId(id);
		}
		sequenceData.setSeq(sequenceData.getSeq() + 1);
		genericService.merge(sequenceData);
		return sequenceData.getSeq();
	}
}